import { R, RX, $ } from "../lib/plugin";
// Chat只管发送数据和接收数据的操作, 具体该何时发送数据,交由Room决定
class Chat {
  constructor(dom, option) {
    let user = R.prop("user", option);
    let assistant = R.prop("assistant", option);
    this.user_id = R.prop("id", user);
    this.user_avatar = R.prop("avatar", user);
    this.user_name = R.prop("name", user);
    this.assistant_id = R.prop("id", assistant);
    this.assistant_avatar = R.prop("avatar", assistant);
    this.assistant_name = R.prop("name", assistant);
    this.room_id = R.prop("room_id", option);
  }
  dom;
  message;
  user_id;
  user_avatar;
  user_name;
  assistant_id;
  assistant_avatar;
  assistant_name;
  room_id;
  talk_item = {};
  talk_list = new Proxy([], {
    get: function (target, prop) {
      if (prop === "push") {
        return function (value) {
          console.log("receive message:", value);
          target.push(value);
        };
      }
      return target[prop];
    },
    set: function (target, prop, value) {
      console.log("receive message:", value);
      target.push(value);
    },
  });
  word_list = new Proxy([], {
    get: function (target, prop) {
      if (prop === "push") {
        return function (value) {
          console.log("receive word(get):", value);
          target.push(value);
        };
      }
      return target[prop];
    },
    set: function (target, prop, value) {
      console.log("receive word(push):", value);
      target.push(value);
    },
  });
  domInit() {
    this.dom.classList.add("chat");
    let el_header = $("<div class='chat-header'></div>");
  }
  onSend(message, handler) {
    return handler(message);
  }
  receiveSteam(conversation_id, word) {
    // 一个词一个词的发送
    this.word_list.push(word); // 接受用户的数据
  }
  stopReceive() {
    let el_stop = document.createElement("div");
    el_stop.innerHTML = "停止接收";
    el_stop.addEventListener("click", () => {});
    return RX.fromEvent(el_stop, "click");
  }
}

export default Chat;
